package cn.edu.scujcc.helloworld;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/channel")
public class ChannelController {
	@Autowired
	private ChannelService service;
	
	@PostMapping("/addhot/{channelId}")
	public Channel addHotComent(@PathVariable String channelId,@RequestBody Coment c) {
		Channel result = null;
		result =service.addHotComment(channelId, c);
		return result;
		
		
	}
	
	@GetMapping("/{id}")
	public Channel getChannel(@PathVariable String id) {
		Channel result = service.getChannel(id);
		return result;
		
	}
	
	@GetMapping()
	public List<Channel> getAllChannels() {
			List<Channel> result = service.getALLChannel();
			return result;
		}
	
	@DeleteMapping("/{id}")
	public boolean deleteChannle(@PathVariable String id) {
		boolean result = false;
		result = service.deleteChannel(id);
		return result;
	}
	
	@PostMapping
	public Channel creatChannels(@RequestBody Channel c) {
		Channel result = null;
		result =service.crateChannel(c);
		return result;
	}
	
	@PutMapping
	public Channel updateChannels(@RequestBody Channel c) {
		Channel result = null;
		result = service.updateChannel(c);
		return result;
	}
	
	@GetMapping("/desc/{desc}")
	public List<Channel> searchByDesc(@PathVariable String desc){
		List<Channel> result = null;
		result = service.searchByDesc(desc);
		return result;
	}
	
	@GetMapping("/name/{name}")
	public List<Channel> searchByName(@PathVariable String name){
		List<Channel> result = null;
		result = service.searchByName(name);
		return result;
	}
	
}
